﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Diagnostics;

using System.Threading;

namespace VisualCrypto
{
    class Algo : Utility
    {
        /* MonoAlgorithm */
        public static Bitmap[] MonoAlgorithmEncryption(Bitmap image1)
        {
            Bitmap convertedBitmap = make_bw(image1);

            Bitmap[] bitmaps = new Bitmap[2];

            Random random = new Random();

            bitmaps[0] = new Bitmap(convertedBitmap.Width * 2, convertedBitmap.Height * 2);
            bitmaps[1] = new Bitmap(convertedBitmap.Width * 2, convertedBitmap.Height * 2);

            for (int y = 0; y < convertedBitmap.Height; y++)
            {
                for (int x = 0; x < convertedBitmap.Width; x++)
                {
                    Color pixel = convertedBitmap.GetPixel(x, y);

                    int set = random.Next(BlackPixelTranslation1.Length);

                    for (int j = 0; j < BlackPixelTranslation1[0].Length; j++)
                    {
                        for (int i = 0; i < BlackPixelTranslation1[0][0].Length; i++)
                        {
                            byte value1, value2;

                            // Black Pixel.
                            if (pixel.R == 0)
                            {
                                value1 = (byte)(BlackPixelTranslation1[set][i][j] * 255);
                                value2 = (byte)(BlackPixelTranslation2[set][i][j] * 255);
                            }

                            // White Pixel.
                            else
                            {
                                value1 = (byte)(WhitePixelTranslation1[set][i][j] * 255);
                                value2 = (byte)(WhitePixelTranslation2[set][i][j] * 255);
                            }

                            bitmaps[0].SetPixel((x * BlackPixelTranslation1[0][0].Length) + i, (y * BlackPixelTranslation1[0].Length) + j, Color.FromArgb(value1, value1, value1));
                            bitmaps[1].SetPixel((x * BlackPixelTranslation1[0][0].Length) + i, (y * BlackPixelTranslation1[0].Length) + j, Color.FromArgb(value2, value2, value2));
                        }
                    }
                }
            }

            return bitmaps;
        }
        public static void MonoAlgoDec(Bitmap image1, Bitmap image2, ChildForm Me, PictureBox picbox)
        {
           
            Bitmap image3 = new Bitmap(image1.Width, Math.Max(image1.Height, image2.Height));
            Bitmap image4 = new Bitmap(image1.Width, Math.Max(image1.Height, image2.Height));
            for (int i = 0; i <= image1.Width; i += 1)
            {
                image2.MakeTransparent();

                using (Graphics g = Graphics.FromImage(image3))
                {
                    g.DrawImage(image1, 0, 0);
                    g.DrawImage(image2, image1.Width - i, 0);
                }
                image4 = image3;
                if (Me.InvokeRequired)
                {
                    Thread.Sleep(1);
                    picbox.Invoke(new Action(() => picbox.Image = (Image)image4));
                }
                else
                {
                    picbox.Image = image4;
                }
               
                
            }
        }
        /* Algorithm #2*/





        /* Algorithm #3 */

    
    
    }
}
